﻿using DevExpress.XtraEditors;
using DXApplicationTangche.UC.下单MTO.Service;
using DXApplicationTangche.UC.客户CRM.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.客户CRM.高德
{
    public partial class XtraUserControl客户地址 : DevExpress.XtraEditors.XtraUserControl
    {
        private GuideDTO guide = new GuideDTO();
        public XtraUserControl客户地址()
        {
            InitializeComponent();
            this.省份();
        }

        private void 省份()
        {
            List<AreaDetailDTO> areaDetailDTOs = MTO订单Service.getAreaDetail("7");
            foreach (AreaDetailDTO item in areaDetailDTOs)
            {
                this.comboBox省份.Items.Add(item.name);
            }
        }

        private void comboBox省份_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(this.comboBox省份.Text))
            {
                return;
            }
            //  高德查询行政区
            this.guide = 高德地址Service.行政区查询(this.comboBox省份.Text);
            //  省份变化相关市、区变化
            this.comboBox城市.Items.Clear();
            this.comboBox区县.Items.Clear();
            foreach (DistrictDTO item in guide.districts[0].districts)
            {
                this.comboBox城市.Items.Add(item.name);
            }
        }

        private void comboBox城市_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(this.comboBox城市.Text))
            {
                return;
            }
            this.comboBox区县.Items.Clear();
            foreach (DistrictDTO item in guide.districts[0].districts)
            {
                if (this.comboBox城市.Text.Equals(item.name))
                {
                    foreach (DistrictDTO dTO in item.districts)
                    {
                        this.comboBox区县.Items.Add(dTO.name);
                    }
                    break;
                }
            }
        }
    }
}
